package cool.tianyou.blue.bird.common.model.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;


/**
 * Api 接口通用返回
 *
 * @author likeugo
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestApiResult<T> {


    /**
     * 返回码
     *
     * @see HttpStatus
     */
    private int code;

    /**
     * 是否成功
     */
    private boolean success;

    /**
     * 提示消息
     */
    private String message;

    /**
     * 返回实体
     */
    private T data;

    public static <T> RestApiResult<T> success(T data) {
        return new RestApiResult<>(HttpStatus.OK.value(), true, "操作成功", data);
    }

    public static <T> RestApiResult<T> success(T data, String message) {
        return new RestApiResult<>(HttpStatus.OK.value(), true, message, data);
    }

    public static <T> RestApiResult<T> failed(T data) {
        return new RestApiResult<>(HttpStatus.OK.value(), false, "操作成功", data);
    }

    public static <T> RestApiResult<T> failed(T data, String message) {
        return new RestApiResult<>(HttpStatus.OK.value(), false, message, data);
    }

    public static <T> RestApiResult<T> isSuccess(T body, Boolean flag, String message) {
        return new RestApiResult<>(HttpStatus.OK.value(), flag, message, body);
    }
}
